package com.archgeek.calcite;

import org.apache.calcite.schema.Schema;
import org.apache.calcite.schema.SchemaFactory;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.impl.ScalarFunctionImpl;

import java.util.Map;

/**
 * @author pizhihui
 * @date 2024-05-30 22:49
 */
public class InMemorySchemaFactory implements SchemaFactory {
    @Override
    public Schema create(SchemaPlus parentSchema, String name, Map<String, Object> operand) {
        System.out.println("schema: " + name);
        System.out.println("operand: " + operand);

        /**
         * 注册函数
         */
        parentSchema.add("SQUARE_FUNC", ScalarFunctionImpl.create(MathFunction.class, "square"));
        parentSchema.add("STRING_FUNC", ScalarFunctionImpl.create(StringFunction.class, "parseString"));
        parentSchema.add("CONCAT_FUNC", ScalarFunctionImpl.create(StringFunction.class, "concat"));


        return new InMemorySchema(name, operand);
    }
}
